feat(editor): Implement dynamic type loading for TS/JS autocompletion #6425
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces the initial implementation of a dynamic type acquisition system to improve the autocompletion experience for TypeScript and JavaScript files.
Currently, the editor relies on static, bundled type definitions (
web-types.ts
), which are often outdated and limited to a few pre-defined libraries likeethers
andweb3
.With this change, when a user imports an NPM package (e.g.,
import { ethers } from 'ethers'
), the system automatically fetches the corresponding type definitions (.d.ts
) from a CDN (unpkg
) and injects them into the editor. This provides an up-to-date, VS Code-like autocompletion experience for a wide range of libraries.Implementation Details
Editor
Plugin (editor.js
):_onChange
method now debounces user input and triggers the type loading process for.ts
and.js
files.moduleResolution
,typeRoots
) on activation to enable Node.js-style module resolution.type-fetcher.ts
Service:.d.ts
files for a given package.package.json
) and internal relative file imports within packages.tsCompletionProvider.ts
:getCompletionsAtPosition
) to provide accurate suggestions, separating its logic from the existing Solidity provider.Current Status & Next Steps
This is an initial version to establish the core architecture and prove the concept. The following tasks remain:
Viem Import Test Code
You can test it using the following code.
Autocomplete is not yet complete.
Related Issues
Fixes #6410